﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using System.Web.Caching;
using mds.NoSqlDatabaseService;
using mds.DFSClient;


namespace mds.DFSWebService.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "修改此模板以快速启动你的 ASP.NET MVC 应用程序。";

            return View();
        }
        public ActionResult Retrieve(String ks, String fid, String ext)
        {
           
            DFSFile file = FileWebCache.Instance.Get(fid);
            if (file == null)
            {
                var key = new DfsPath(ks, fid, ext);
                file = Dfs.GetFile(key);
                FileWebCache.Instance.Store(file);
            }            
            return File(file.FileData, file.FileExtension, file.FileFullName);
        }
        public ActionResult Download(String ks, String fid, String ext)
        {
            DFSFile file = FileWebCache.Instance.Get(fid);
            if (file == null)
            {
                var key = new DfsPath(ks, fid, ext);
                file = Dfs.GetFile(key);
                FileWebCache.Instance.StoreDownload(file);
            }     
            return File(file.FileData, file.FileExtension, file.FileFullName);
        }
    }
}
